package com.cloud.client.controller;

import com.cloud.client.service.FileService;
import com.cloud.client.util.AjaxResult;
import com.cloud.client.util.MapPro;
import com.cloud.client.util.MapUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

/**
 * @packageName: com.cloud.client.controller
 * @name: FileController
 * @description:
 * @author: 董定卓
 * @dateTime: 2019/7/15 15:53
 */
@RestController
public class FileController {

    @Autowired
    FileService service;

    /**
     * 上传文件
     *
     * @param map
     * @param file
     * @return
     */
    @PostMapping(value = "/fileUpload")
    public Object fileUpload(@RequestParam Map<String, Object> map, @RequestParam("file") MultipartFile file) {
        String token = MapUtil.getString(map, "token");
        if (token == null) {
            return AjaxResult.failResult("token不能为空");
        }
        String system = MapUtil.getString(map, "system");
        if (system == null) {
            return AjaxResult.failResult("系统代码不能为空");
        }
        String type = MapUtil.getString(map, "type");
        if (type == null) {
            return AjaxResult.failResult("文件类型不能为空");
        }
        return service.fileUpload(map, file);
    }

    /**
     * 文件信息分页列表
     *
     * @param map
     * @return
     */
    @PostMapping("/filePage")
    public Object filePage(@RequestParam Map<String, Object> map) {
        String token = MapUtil.getString(map, "token");
        if (token == null) {
            return AjaxResult.failResult("token不能为空");
        }
        return service.filePage(map);
    }

    public static void main(String[] args) {
        MapPro mapPro = new MapPro();
        mapPro.put("a",1111).put("b","abc222");
        HashMap map = mapPro.getMap();
        System.out.println(map);
    }

}
